package com.sky.service.impl;

/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/6/3 20:53
 * @Version: 1.0
 */

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.service.CategoryService;
import com.sky.utils.CurrentHolderUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/6/3 20:53
 * @Version: 1.0
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
   private CategoryMapper categoryMapper;


    /**
     * 新增种类
     * @param categoryDTO
     * @return
     */
    @Override
    public void save(CategoryDTO categoryDTO) {
        Category category = new Category();
        BeanUtils.copyProperties(categoryDTO,category);

        category.setStatus(1);

       // category.setCreateTime(LocalDateTime.now());
      //  category.setUpdateTime(LocalDateTime.now());
      //  category.setCreateUser(CurrentHolderUtil.getCurrentId());
      //  category.setUpdateUser(CurrentHolderUtil.getCurrentId());
        categoryMapper.insert(category);
    }

    /**
     * 种类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
        Page<Category> page = categoryMapper.pageQuery(categoryPageQueryDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 删除种类
     * @param id
     * @return
     */
    @Override
    public void deleteById(Long id) {
        categoryMapper.deleteById(id);

    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @Override
    public void updateCategory(CategoryDTO categoryDTO) {
        Category category = new Category();
        BeanUtils.copyProperties(categoryDTO,category);
        category.setStatus(0);
     //   category.setUpdateTime(LocalDateTime.now());
      //  category.setCreateUser(CurrentHolderUtil.getCurrentId());
        categoryMapper.update(category);
    }
    /**
     * 启用禁用分类
     * @param status
     * @param id
     * @return
     */
    @Override
    public void startOrStop(Integer status, long id) {
        Category category = new Category();
        category.setStatus(status);
        category.setId(id);
        categoryMapper.update(category);
    }


    @Override
    public List<Category> QueryClassificationByType(Integer type) {
        List<Category> categoryList= categoryMapper.QueryClassificationByType(type);
             return categoryList;
    }

    @Override
    public Integer count(Long categoryId) {
        return categoryMapper.count(categoryId);
    }


}
